package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.PmsPurchase;
import com.ruoyi.system.service.IPmsPurchaseService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购单Controller
 *
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/purchase")
@CrossOrigin
public class PmsPurchaseController extends BaseController
{
    @Autowired
    private IPmsPurchaseService pmsPurchaseService;

    /**
     * 查询采购单列表
     */
    @RequiresPermissions("system:purchase:list")
    @GetMapping("/list")
    public TableDataInfo list(PmsPurchase pmsPurchase)
    {
        startPage();
        List<PmsPurchase> list = pmsPurchaseService.selectPmsPurchaseList(pmsPurchase);
        return getDataTable(list);
    }

    /**
     * 导出采购单列表
     */
    @RequiresPermissions("system:purchase:export")
    @Log(title = "采购单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsPurchase pmsPurchase)
    {
        List<PmsPurchase> list = pmsPurchaseService.selectPmsPurchaseList(pmsPurchase);
        ExcelUtil<PmsPurchase> util = new ExcelUtil<PmsPurchase>(PmsPurchase.class);
        util.exportExcel(response, list, "采购单数据");
    }

    /**
     * 获取采购单详细信息
     */
    @RequiresPermissions("system:purchase:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmsPurchaseService.selectPmsPurchaseById(id));
    }

    /**
     * 新增采购单
     */
    @RequiresPermissions("system:purchase:add")
    @Log(title = "采购单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsPurchase pmsPurchase)
    {
        return toAjax(pmsPurchaseService.insertPmsPurchase(pmsPurchase));
    }

    /**
     * 修改采购单
     */
    @RequiresPermissions("system:purchase:edit")
    @Log(title = "采购单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsPurchase pmsPurchase)
    {
        return toAjax(pmsPurchaseService.updatePmsPurchase(pmsPurchase));
    }

    /**
     * 删除采购单
     */
    @RequiresPermissions("system:purchase:remove")
    @Log(title = "采购单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsPurchaseService.deletePmsPurchaseByIds(ids));
    }
}
